<html>
<head>
<title>E:\QProjects\Lisp\toygen\inter\types-utility.lisp.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#804040"> 1 </font><span class="Comment">;</span>
<font color="#804040"> 2 </font><span class="Comment">; utilities to work with types</span>
<font color="#804040"> 3 </font><span class="Comment">;</span>
<font color="#804040"> 4 </font><span class="Comment">;</span>
<font color="#804040"> 5 </font><span class="Comment">;</span>
<font color="#804040"> 6 </font>
<font color="#804040"> 7 </font>
<font color="#804040"> 8 </font>
<font color="#804040"> 9 </font>
<font color="#804040">10 </font>
<font color="#804040">11 </font><span class="Comment">;</span>
<font color="#804040">12 </font><span class="Comment">; converts given symbol type to its string equivalent</span>
<font color="#804040">13 </font><span class="Comment">;</span>
<font color="#804040">14 </font><span class="Special">(</span><span class="Statement">defun</span><span class="lispList"> </span><span class="lispSymbol">symbol-type-to-string</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">sym-type</span><span class="Special">)</span>
<font color="#804040">15 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">let</span><span class="lispList"> </span><span class="Special">((</span><span class="lispSymbol">type-info</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">get-type-info</span><span class="lispList"> </span><span class="lispSymbol">sym-type</span><span class="Special">)))</span>
<font color="#804040">16 </font><span class="lispLeadWhite">    </span><span class="Special">(</span><span class="lispSymbol">type-info-lang-name</span><span class="lispList"> </span><span class="lispSymbol">type-info</span><span class="Special">)</span>
<font color="#804040">17 </font><span class="lispLeadWhite">    </span><span class="Special">))</span>
<font color="#804040">18 </font>
<font color="#804040">19 </font><span class="Special">(</span><span class="Statement">defun</span><span class="lispList"> </span><span class="lispSymbol">list-type-to-string</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">complex-type</span><span class="Special">)</span>
<font color="#804040">20 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">assert</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">and</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">listp</span><span class="lispList"> </span><span class="lispSymbol">complex-type</span><span class="Special">)</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">=</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">length</span><span class="lispList"> </span><span class="lispSymbol">complex-type</span><span class="Special">)</span><span class="lispList"> </span><span class="Constant">2</span><span class="Special">)))</span>
<font color="#804040">21 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">let</span><span class="lispList"> </span><span class="Special">((</span><span class="lispSymbol">type-modifier</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">first</span><span class="lispList"> </span><span class="lispSymbol">complex-type</span><span class="Special">)))</span>
<font color="#804040">22 </font><span class="lispLeadWhite">    </span><span class="Special">(</span><span class="Statement">cond</span>
<font color="#804040">23 </font><span class="lispLeadWhite">     </span><span class="Special">((</span><span class="Statement">eq</span><span class="lispList"> </span><span class="lispSymbol">type-modifier</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">ptr</span><span class="Special">)</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">concatenate</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">string</span>
<font color="#804040">24 </font><span class="lispLeadWhite">                                           </span><span class="Special">(</span><span class="lispSymbol">stringify-typename</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">second</span><span class="lispList"> </span><span class="lispSymbol">complex-type</span><span class="Special">))</span>
<font color="#804040">25 </font><span class="lispLeadWhite">                                           </span><span class="Constant">&quot; &quot;</span><span class="lispList"> </span><span class="Comment">; delimeter</span>
<font color="#804040">26 </font><span class="lispLeadWhite">                                           </span><span class="Constant">&quot;*&quot;</span><span class="lispList"> </span><span class="Comment">; pointer specifier</span>
<font color="#804040">27 </font><span class="lispLeadWhite">                                           </span><span class="Special">))</span>
<font color="#804040">28 </font><span class="lispLeadWhite">     </span><span class="Special">((</span><span class="Statement">eq</span><span class="lispList"> </span><span class="lispSymbol">type-modifier</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">const</span><span class="Special">)</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">concatenate</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">string</span>
<font color="#804040">29 </font><span class="lispLeadWhite">                                             </span><span class="Constant">&quot;const&quot;</span><span class="lispList"> </span><span class="Comment">; const specifier</span>
<font color="#804040">30 </font><span class="lispLeadWhite">                                             </span><span class="Constant">&quot; &quot;</span><span class="lispList"> </span><span class="Comment">; delimeter</span>
<font color="#804040">31 </font><span class="lispLeadWhite">                                             </span><span class="Special">(</span><span class="lispSymbol">stringify-typename</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">second</span><span class="lispList"> </span><span class="lispSymbol">complex-type</span><span class="Special">))</span>
<font color="#804040">32 </font><span class="lispLeadWhite">                                             </span><span class="Special">))</span>
<font color="#804040">33 </font><span class="lispLeadWhite">     </span><span class="Special">(</span><span class="Statement">t</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">error</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">format</span><span class="lispList"> </span><span class="Statement">nil</span><span class="lispList"> </span><span class="Constant">&quot;unknown type modifier: ~a&quot;</span><span class="lispList"> </span><span class="lispSymbol">type-modifier</span><span class="Special">)))</span>
<font color="#804040">34 </font><span class="lispLeadWhite">     </span><span class="Special">)))</span>
<font color="#804040">35 </font>
<font color="#804040">36 </font><span class="Special">(</span><span class="Statement">defun</span><span class="lispList"> </span><span class="lispSymbol">stringify-typename</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">typename</span><span class="Special">)</span>
<font color="#804040">37 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">if</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">symbolp</span><span class="lispList"> </span><span class="lispSymbol">typename</span><span class="Special">)</span>
<font color="#804040">38 </font><span class="lispLeadWhite">      </span><span class="Special">(</span><span class="lispSymbol">symbol-type-to-string</span><span class="lispList"> </span><span class="lispSymbol">typename</span><span class="Special">)</span>
<font color="#804040">39 </font><span class="lispLeadWhite">    </span><span class="Special">(</span><span class="lispSymbol">list-type-to-string</span><span class="lispList"> </span><span class="lispSymbol">typename</span><span class="Special">)</span>
<font color="#804040">40 </font><span class="lispLeadWhite">    </span><span class="Special">))</span>
<font color="#804040">41 </font>
<font color="#804040">42 </font><span class="Special">(</span><span class="Statement">defun</span><span class="lispList"> </span><span class="lispSymbol">stringify-symbol-name</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">sym-name</span><span class="Special">)</span>
<font color="#804040">43 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">assert</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">symbolp</span><span class="lispList"> </span><span class="lispSymbol">sym-name</span><span class="Special">))</span>
<font color="#804040">44 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">format</span><span class="lispList"> </span><span class="Statement">nil</span><span class="lispList"> </span><span class="Constant">&quot;~(~a~)&quot;</span><span class="lispList"> </span><span class="lispSymbol">sym-name</span><span class="Special">)</span><span class="lispList"> </span><span class="Comment">; make lowercase</span>
<font color="#804040">45 </font><span class="lispLeadWhite">  </span><span class="Special">)</span>
<font color="#804040">46 </font>
<font color="#804040">47 </font><span class="Comment">;</span>
<font color="#804040">48 </font><span class="Comment">; stringifies arguments list</span>
<font color="#804040">49 </font><span class="Comment">;</span>
<font color="#804040">50 </font><span class="Special">(</span><span class="Statement">defun</span><span class="lispList"> </span><span class="lispSymbol">stringify-arg-list</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">args</span><span class="Special">)</span>
<font color="#804040">51 </font><span class="lispLeadWhite">  </span><span class="Special">(</span><span class="Statement">let</span><span class="lispList"> </span><span class="Special">((</span><span class="lispSymbol">result</span><span class="lispList"> </span><span class="Constant">&quot;(&quot;</span><span class="Special">)</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">is-first</span><span class="lispList"> </span><span class="Statement">t</span><span class="Special">))</span>
<font color="#804040">52 </font><span class="lispLeadWhite">    </span><span class="Special">(</span><span class="Statement">dolist</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">arg</span><span class="lispList"> </span><span class="lispSymbol">args</span><span class="Special">)</span>
<font color="#804040">53 </font><span class="lispLeadWhite">      </span><span class="Special">(</span><span class="Statement">let</span><span class="lispList"> </span><span class="Special">(</span>
<font color="#804040">54 </font><span class="lispLeadWhite">            </span><span class="Special">(</span><span class="lispSymbol">type-decl</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">stringify-typename</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">first</span><span class="lispList"> </span><span class="lispSymbol">arg</span><span class="Special">)))</span><span class="lispList"> </span><span class="Comment">; type decl in the args list</span>
<font color="#804040">55 </font><span class="lispLeadWhite">            </span><span class="Special">(</span><span class="lispSymbol">arg-name</span><span class="lispList"> </span><span class="Special">(</span><span class="lispSymbol">stringify-symbol-name</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">second</span><span class="lispList"> </span><span class="lispSymbol">arg</span><span class="Special">)))</span><span class="lispList"> </span><span class="Comment">; arg name itself</span>
<font color="#804040">56 </font><span class="lispLeadWhite">            </span><span class="Special">)</span>
<font color="#804040">57 </font><span class="lispLeadWhite">        </span><span class="Special">(</span><span class="Statement">if</span><span class="lispList"> </span><span class="lispSymbol">is-first</span>
<font color="#804040">58 </font><span class="lispLeadWhite">            </span><span class="Special">(</span><span class="Statement">setf</span><span class="lispList"> </span><span class="lispSymbol">is-first</span><span class="lispList"> </span><span class="Statement">nil</span><span class="Special">)</span>
<font color="#804040">59 </font><span class="lispLeadWhite">          </span><span class="Special">(</span><span class="Statement">setf</span><span class="lispList"> </span><span class="lispSymbol">result</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">concatenate</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">string</span><span class="lispList"> </span><span class="lispSymbol">result</span><span class="lispList"> </span><span class="Constant">&quot;,&quot;</span><span class="Special">))</span>
<font color="#804040">60 </font><span class="lispLeadWhite">          </span><span class="Special">)</span>
<font color="#804040">61 </font><span class="lispLeadWhite">        </span><span class="Special">(</span><span class="Statement">setf</span><span class="lispList"> </span><span class="lispSymbol">result</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">concatenate</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">string</span>
<font color="#804040">62 </font><span class="lispLeadWhite">                                  </span><span class="lispSymbol">result</span>
<font color="#804040">63 </font><span class="lispLeadWhite">                                  </span><span class="Special">(</span><span class="Statement">format</span><span class="lispList"> </span><span class="Statement">nil</span><span class="lispList"> </span><span class="Constant">&quot; ~a ~a&quot;</span><span class="lispList"> </span><span class="lispSymbol">type-decl</span><span class="lispList"> </span><span class="lispSymbol">arg-name</span><span class="Special">)))</span>
<font color="#804040">64 </font><span class="lispLeadWhite">        </span><span class="Special">))</span>
<font color="#804040">65 </font><span class="lispLeadWhite">    </span><span class="Special">(</span><span class="Statement">concatenate</span><span class="lispList"> </span><span class="Special">'</span><span class="Identifier">string</span><span class="lispList"> </span><span class="lispSymbol">result</span><span class="lispList"> </span><span class="Special">(</span><span class="Statement">if</span><span class="lispList"> </span><span class="lispSymbol">is-first</span><span class="lispList"> </span><span class="Constant">&quot;)&quot;</span><span class="lispList"> </span><span class="Constant">&quot; )&quot;</span><span class="Special">))))</span>
</pre>
</body>
</html>
